<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>模型验证</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link type="text/css" rel="stylesheet" href="plugin/layui/css/layui.css">
    <link type="text/css" rel="stylesheet" href="css/common.css">
    <link type="text/css" rel="stylesheet" href="css/create.css">
    <!--该js引用需要放在所有js之前-->
    <script src="js/resource.js"></script>
</head>
<body>

<section class="layui-section-1">
    <div class="layui-section-title">
        模型管理
    </div>
</section>
<section class="layui-section-2">
    <table id="useCaseList" lay-filter="useCaseList"></table>
</section>
<section class="layui-section-3">
    <iframe style="width: 100%;" class="larry-iframe" data-id='0' name="ifr_0" id='ifr0' src="add.html"></iframe>
    <div style="clear:both;"></div>
</section>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>
<script id="toolbar_head" type="text/html">
    <div class="layui-btn-container">
        <!--<button class="layui-btn layui-btn-sm" lay-event="add">
            <i class="layui-icon">&#xe654;&nbsp;新&nbsp;增</i>
        </button>-->
        <button class="layui-btn layui-btn-sm" lay-event="choose">
            <i class="layui-icon">&#xe608;&nbsp;提&nbsp;交</i>
        </button>
    </div>
</script>
<script src="plugin/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base: 'js/lib/'
    }).extend({
        common: 'common'
    });
    layui.use(['jquery', 'element', 'common', 'table', 'form', 'laytpl'], function () {
        var form = layui.form;
        $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            element = layui.element,
            common = layui.common,
            globalReqJson = "";
        table.set({
            page: true,
            limits: [15, 50, 100, 200],
            limit: 15,
            loading: true,
            height: 'auto',
            even: true,
            size: 'sm',
            method: 'post'
        });
        var funcs = {
            //初始化用列列表
            init: function () {
                var width = $(".layui-section-2").width();
                table.render({
                    width: width,
                    id: 'useCaseList',
                    toolbar: '#toolbar_head',
                    elem: '#useCaseList',
                    url: globalParam.getUrl("create", "getUseCaseList"),
                    cols: [[
                        {type: 'radio'},
                        {title: '操作', width: width / 4, align: 'center', toolbar: '#toolBar'},
                        {field: 'createTime', title: '时间', width: width / 4},
                        {field: 'templateDescribe', title: '描述', width: 2 * width / 4}
                    ]]
                });
                table.on('tool(useCaseList)', function (obj) {
                    var data = obj.data, //获得当前行数据
                        layEvent = obj.event, //获得 lay-event 对应的值
                        tr = obj.tr; //获得当前行 tr 的DOM对象
                    if (layEvent === 'del') {
                        layer.confirm('确定对该用例删除?', function (index) {
                            layer.close(index);
                            table.reload('useCaseList');
                        });
                    }else if(layEvent === 'edit'){
                        $("#ifr0").attr("src","editTemp.html?modelId="+data.id+"&modelName="+window.encodeURI(window.encodeURI(data.templateDescribe)));
                    }
                });
                return this;
            },
            //获取父页面请求json
            gerReqJson : function(){
                globalReqJson = $(top.document).find("textarea[name='request']").html();
                return this;
            },
            //toolbar事件
            toolbarFunc: function () {
                table.on('toolbar(useCaseList)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                    switch (obj.event) {
                        case 'choose':
                            var data = checkStatus.data;  //获取选中行数据
                            if(!data || data.length<=0){
                                common.cmsError("请选择模型!","错误");
                                break;
                            }
                            layer.confirm('确定选择该模型作为该次测试?', function (index) {
                                layer.close(index);
                                common.cmsAjax({
                                    url: globalParam.getUrl("create", "choose"),
                                    data: {
                                        templateId: data[0].id || "",
                                        enterParam : globalReqJson || "",
                                    },
                                    successFunc: function (res) {
                                        var useCaseEle = $(parent.document).find("#useCase"),
                                            useCaseFormItem = $(parent.document).find("#useCaseFormItem");
                                        useCaseFormItem.show('fast',function () {
                                            useCaseEle.html('模型名称 ：&nbsp;<span style="color:red">'+data[0].templateDescribe+'</span>');
                                            useCaseEle.next().val(data[0].id);
                                            parent.layer.closeAll();
                                        });
                                    }
                                });
                            });
                            break;
                        case 'add':

                            break;
                        default:
                            break;
                    };
                });
                return this;
            },
            ifrSetFunc : function(){
                $("#ifr0").height($(window).height()*1.5);
                return this;
            }
        };
        funcs.gerReqJson().init().ifrSetFunc().toolbarFunc();


    });
</script>
</body>
</html>